#pragma once
#include "HuffmanTree.hpp"
#include "Common.h"
#include <string>
using std::string;

struct ByteInfo
{
	uch _ch;
	size_t _appearCount;
	std::string _chCode;
	ByteInfo(size_t appearCount = 0)
		:_appearCount(appearCount)
	{}

	ByteInfo operator+(const ByteInfo& other)const
	{
		return ByteInfo(_appearCount + other._appearCount);
	}

	bool operator>(const ByteInfo& other)const
	{
		return _appearCount > other._appearCount;
	}

	bool operator!=(const ByteInfo& other)const
	{
		return _appearCount != other._appearCount;
	}
	bool operator==(const ByteInfo& other)const
	{
		return _appearCount == other._appearCount;
	}
};

class FileComperssHM
{
public:
	FileComperssHM();
	void CompressFile(const string& filePath);
	void UNCompressFile(const string& filePath);
	string GetFilePostFix(const string& filePath);
	void GetLine(FILE* fIn, string& strInfo);
private:
	void GenerateHuffmanCode(HuffmanTreeNode<ByteInfo>* root);
	void WriteHeadInfo(const string& filePath, FILE* fOut);
	std::vector<ByteInfo> _fileInfo;
};